home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11766 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.8 KB  |  98 lines

  1. Path: tick.cs.wm.edu!news
  2. From: mhagger@yellow.physics.wm.edu (Michael Haggerty)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Inheritance and function signatures
  5. Date: 15 Mar 1996 20:54:31 -0500
  6. Organization: College of William and Mary
  7. Sender: mhagger@yellow.physics.wm.edu
  8. Message-ID: <x1lol1x0o8.fsf@yellow.physics.wm.edu>
  9. References: <MANOWAR.96Mar11132010@dilo.engin.umich.edu>
  10.     <3146D380.2781@rchland.ibm.com>
  11. Reply-To: mhagger@mail.delos.physics.wm.edu
  12. NNTP-Posting-Host: yellow.physics.wm.edu
  13. In-reply-to: Philip Staite's message of Wed, 13 Mar 1996 07:54:08 -0600
  14. X-Newsreader: Gnus v5.1
  15.  
  16. Hello,
  17.  
  18. In article <3146D380.2781@rchland.ibm.com> Philip Staite
  19. <pstaite+@rchland.ibm.com> writes:
  20.  
  21. > Basically within the scope of B the print(int,int) "captures" the name
  22. > print -- all references to print() go to it.  Here's the FAQ that covers
  23. > this:
  24. > ===========================================================================
  25. > Q63: What's the meaning of, "Warning: Derived::f(int) hides
  26. > Base::f(float)"?
  27. > It means you're going to die.
  28. > Here's the mess you're in: if Derived declares a member function
  29. > named "f", and Base declares a member function named "f" with a
  30. > different signature (e.g., different parameter types and/or
  31. > constness), then the Base "f" is "hidden" rather than "overloaded"
  32. > or "overridden" (even if the Base "f" is virtual).
  33. > Here's how you get out of the mess: Derived must redefine the Base
  34. > member function(s) that are hidden (even if they are non-virtual).
  35. > Normally this re-definition merely calls the appropriate Base member
  36. > function.  E.g.,
  37. >     class Base {
  38. >     public:
  39. >       void f(int);
  40. >     };
  41. >     class Derived : public Base {
  42. >     public:
  43. >       void f(double);
  44. >       void f(int i) { Base::f(i); }
  45. >     };             // ^^^^^^^^^^--- redefinition merely calls Base::f(int)
  46. > ===========================================================================
  47.  
  48. I have a question on this point.
  49.  
  50. Is it sufficient to do the following:
  51.  
  52.     // example 1:
  53.     class Base {
  54.     public:
  55.       void f(int);
  56.     };
  57.  
  58.     class Derived : public Base {
  59.     public:
  60.       Base::f; // put Base::f in Derived's namespace
  61.       void f(double); // add a new signature for f
  62.     };
  63.  
  64. ?  If not, why not?  It seems to me that this is a good and logical
  65. feature.
  66.  
  67. The reason it would be nice is for the case of an abstract base class
  68. hierarchy:
  69.  
  70.     // example 2:
  71.     class Base {
  72.     public:
  73.       virtual void f(int) = 0;
  74.     };
  75.  
  76.     class Derived : public Base {
  77.     public:
  78.       virtual void f(double) = 0;
  79.       void f(int i) { Base::f(i); } // OOPS!
  80.     };
  81.  
  82. As I understand it, example 2 is illegal since it attempts to call
  83. (non-virtually) Base::f(int), which doesn't exist at all.  Or is there
  84. some twist in the rules that makes example 2 legal with the right
  85. behavior?
  86.  
  87. I submit that there ought to be a way to do this...
  88.  
  89. --Michael
  90.